import Particle from './particle';


const FRACTION=(num,mul=1)=>{
    let n=num*mul;
    return n-Math.floor(n);
};

export default class ParticleCube extends Particle{
    constructor(values={}){
        super(values);
        this.props.add({
            endSize:values.endSize||1,
        });
    }
    initPropCallback(){
        super.initPropCallback();
        this.props.onMultiKeyChange(()=>{
            this.endScl=this.props.endSize.value/this.props.startSize.value;
        },'startSize','endSize');
    }
    initVariable(){
        super.initVariable();
        this.endScl=this.props.endSize.value/this.props.startSize.value;
    }
    setStartVertSpeed(rand,i,t){
        this.verts[i]=-this.props.startSize.value+this.props.startSize.value*2*FRACTION(rand,1e4);
        this.verts[i+2]=-this.props.startSize.value+this.props.startSize.value*2*FRACTION(rand,1e5);

        this.speeds[i]=this.verts[i]*this.endScl-this.verts[i];
        this.speeds[i+1]=this.props.speedMin.value+(this.props.speedMax.value-this.props.speedMin.value)*FRACTION(rand,1e6);
        this.speeds[i+2]=this.verts[i+2]*this.endScl-this.verts[i+2];
    }
}